import os

license_comment = "/*\n\
 * This file is part of the asfingerx Project.\n\
 * Copyright (C) 2020 stanley0207@163.com\n\
 *\n\
 * This program is free software: you can redistribute it and/or modify\n\
 * it under the terms of the GNU General Public License as published by\n\
 * the Free Software Foundation, either version 3 of the License, or\n\
 * (at your option) any later version.\n\
 *\n\
 * This program is distributed in the hope that it will be useful,\n\
 * but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\
 * GNU General Public License for more details.\n\
 *\n\
 * You should have received a copy of the GNU General Public License\n\
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\
 */\n\
\n\
"

def add_license(filename):
  with open(filename, "r+") as f:
    old = f.read()
    f.seek(0)
    f.write(license_comment)
    f.write(old)

def add_license_all(path):
  count = 0
  for root, dirs, files in os.walk(path):
    for file in files:
      if file.endswith(".h") or \
        file.endswith(".hpp") or \
        file.endswith(".cpp") or \
        file.endswith(".cc"):
        print(file)
        filename = os.path.join(root, file)
        add_license(filename)
        count += 1
  print("%d files convert." %(count))

if __name__ == "__main__":
  path = './'
  add_license_all(path)
